#include<vector>
#include<algorithm>
using namespace std;

class Solution {
public:
    int findPoisonedDuration(vector<int>& timeSeries, int duration) {
        if (timeSeries.size() == 0)
            return 0;
        int res = 0;
        for (int i = 0; i < timeSeries.size()-1; ++i) {
            res += min(timeSeries[i + 1] - timeSeries[i], duration);
        }
        res += duration;
        return res;
    }
};